<template>
  <div>
    <el-container>
      <!--      左则边栏-->
      <el-aside style="min-height: 100vh;background-color: #001529" :width="asideWidth">
        <div style="height: 60px;color: white;display: flex;align-items: center;justify-content: center">
          <img src="@/assets/logo.png" style="width: 40px;height: 40px"/>
          <span class="logo-title" v-if="!isCollapse">娇健集团</span>
       </div>
        <el-menu
            style="border: none"
            :default-active=$route.path
            router
            background-color="#001529"
            text-color="rgba(255,255,255,0.65)"
            active-text-color="#fff"
            :collapse="isCollapse"
            :collapse-transition="false"
        >

          <el-menu-item index="/home">
            <i class="el-icon-s-home"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-submenu v-if="user.role === '管理员'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/user">
              <template>
                <span slot="title">用户信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/news">
              <template>
                <span slot="title">新闻信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/orders">
              <template>
                <span slot="title">订单信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/notice">
              <template>
                <span slot="title">系统公告</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/logs">
              <template>
                <span slot="title">日志信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/charts">
              <template>
                <span slot="title">数据统计</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!--      右半部分-->
      <el-container>
        <!--        头部区域-->
        <el-header>
          <i :class="icon" style="font-size: 26px;" @click="handleCollapse"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 10px">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: $route.path}">{{ $route.meta.name }}</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex:1;width:0;display: flex;justify-content: flex-end;align-items: center">
            <i class="el-icon-full-screen" style="font-size: 26px" @click="handFulls"></i>
            <el-dropdown placement="bottom">
              <div style="display: flex;align-items: center;cursor: default;margin: 0 8px">
                <span class="el-dropdown-link">
                  <img :src="user.avatar" style="height: 40px;width: 40px;border-radius: 50%">
                </span>
                <span>{{user.name}}</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="()=>$router.push('/person')">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="()=>$router.push('/password')">修改密码</el-dropdown-item>
                <el-dropdown-item ><div @click="logout">退出登陆</div></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <!--        主体区域-->
        <el-main>
          <router-view @update:user="updateUser" />
        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script>


import request from "@/utils/request";

export default {
  name: 'Manager',
  components: {

  },
  data(){
    return {
      isCollapse:false,
      asideWidth:'200px',
      icon:'el-icon-s-fold',
      user:JSON.parse(localStorage.getItem("user") || '{}')
    }
  },
  mounted() {  //页面加载时触发
    // axios.get("http://localhost:9092/user/selectAll").then(res=>{
    //   const {code,data} = res.data
    //   if (code==='200') this.userList=data
    // })
    if (!this.user.id){
      this.$router.push('/login')
    }

    // console.log(this.$route)
    // request.get('/user/selectAll').then(res=>{
    //   this.userList=res.data
    // })
  },
  methods:{
    handFulls(){
      document.documentElement.requestFullscreen() //切换全屏
    },
    handleCollapse(){
      this.isCollapse = !this.isCollapse
      this.asideWidth = this.isCollapse?'64px':'200px'
      this.icon = this.isCollapse? 'el-icon-s-unfold':'el-icon-s-fold'
    },
    logout(){
      localStorage.removeItem("user")
      this.$router.push('/login')
    },
    updateUser(user){
      this.user={...user}
    }

  }
}
</script>

<style>
.el-menu--inline{
  background-color: #000c17 !important;
}
.el-menu--inline .el-menu-item{
  background-color: #000c17 !important;
  padding-left: 49px !important;
}
.el-menu-item:hover,.el-submenu__title:hover{
  color: #fff !important;
}
.el-submenu__title:hover>i,.el-menu-item:hover>i{
  color: #fff;
}
.el-menu-item.is-active{
  background-color:#1890ff !important;
  border-radius: 5px !important;
  width: calc(100% - 8px);
  margin-left: 4px;
}

.el-menu-item.is-active i,.el-menu-item.is-active .el-tooltip{
  margin-left: -4px;
}

.el-menu-item{
  height: 40px !important;
  line-height: 40px !important;

}
.el-submenu .el-menu-item{
  min-width: 0 !important;
}
.el-menu--inline .el-menu-item.is-active{
  padding-left: 45px !important;
}
.el-submenu__title{
  height: 40px !important;
  line-height: 40px !important;
}
.el-submenu__icon-arrow{
  margin-top: -5px !important;
}
/*收缩动画*/
.el-aside{
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0,21,41,.35);
}

.logo-title{
  margin-left: 4px;
  font-size: 20px;
  transition: all .3s;
}

.el-header{
  box-shadow: 2px 0 6px rgba(0,21,41,.35);
  display: flex;
  align-items: center;
}
</style>

